<!--  -->
<template>
  <view class=''>
    <!-- <u-loading-page :loading="true" bg-color="#e8e8e8"></u-loading-page> -->
     <button open-type="getPhoneNumber" @getphonenumber="getNumber"></button>
  </view>
</template>

<script>
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
    data() {
    //这里存放数据
      return {

      };
    },
    onShow(){
      this.getNumber()
    },
    methods: {
      getNumber(e) {
        console.log(e);
        
        let appid = 'wx4d5cebf19bb57d99'
        let secret = '347dcbf0a40cc2ed783c3928ceba6eee'
        uni.request({
            url: 'https://api.weixin.qq.com/cgi-bin/token',
            method: 'GET',
            data: {
                appid,
                secret,
                grant_type: 'client_credential'
            },
            success: (res) => {
                console.log(res);
                let accessToken = res.data.access_token
                uni.request({
                    url: `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${accessToken}`,
                    method: 'POST',
                    // data: {
                    //     code: e.detail.code
                    // },
                    success: (result) => {
                        console.log(result)
                        if(result.data.errcode === 0) {
                            let phone = result.data.phone_info.phoneNumber
                        }
                    },
                    fail() {
                        uni.showToast({
                            title: '获取失败,请重试',
                            icon: 'error'
                        })
                    }
                })
            },
            fail() {
                uni.showToast({
                    title: '获取失败,请重试',
                    icon: 'error'
                })
            }
        })
      }
    }
}
</script>
<style lang='scss' scoped>
  @import "@/common/configStyle.scss";
  .configFontsize {
    font-size: $ruyi-config-fontsize;
    background-color: $ruyi-config-backColor;
    min-height: 100vh;
  }
</style>
